package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.service.ILearningLessonService;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author lcm
 * @since 2023-07-19
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "我的课表相关接口")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> page(@ApiParam("分页参数") PageQuery pageQuery){
        return learningLessonService.queryMyLessons(pageQuery);
    }

    @GetMapping("/now")
    @ApiOperation("查询正在学习的课表")
    public LearningLessonVO now(){
        return learningLessonService.queryNowCourse();
    }

    @GetMapping("/{courseId}")
    @ApiOperation("根据课程id查询状态")
    public LearningLessonVO getStatus(@ApiParam("课程id") @PathVariable Long courseId){
        return learningLessonService.getLessonStatus(courseId);
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("根据课程id删除课程")
    public void deleteCourseById(@ApiParam("课程id") @PathVariable Long courseId){
        learningLessonService.deleteCourseById(courseId);
    }

    @GetMapping("/{courseId}/valid")
    @ApiOperation("根据课程id校验课程是否有效")
    public Long isLessonValid(@ApiParam("课程id") @PathVariable("courseId") Long courseId){
        return learningLessonService.isLessonValid(courseId);
    }

    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@ApiParam("课程id") @PathVariable("courseId") Long courseId){
        return learningLessonService.countLesson(courseId);
    }

    @PostMapping("/plans")
    @ApiOperation("创建学习计划")
    public void createPlans(@ApiParam("每周学习章节数") @Valid @RequestBody LearningPlanDTO learningPlanDTO){
        learningLessonService.createPlans(learningPlanDTO);
    }

    @GetMapping("/plans")
    @ApiOperation("展示学习计划")
    public LearningPlanPageVO showPlans(@ApiParam("学习计划分页参数") PageQuery pageQuery){
        return learningLessonService.showPlans(pageQuery);
    }
}
